<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-header">发布公告</div>
    <div class="layui-card-body" style="">
        <form class="layui-form" action="" onsubmit="return false">
            <div class="layui-form-item">
                <label class="layui-form-label fontColor">选择机柜</label>
                <div class="layui-input-block">
                    <select name="number" lay-search>
                        <option th:each="dict:${hostList}" th:value="${dict.number}" th:text="${dict.number}">
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <textarea name="content" lay-verify="required" lay-reqtext="请输入公告内容" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="standAloneTransmission">单机发送</button>
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="sendAll">发送所有</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'dtree'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        //单机发送
        form.on('submit(standAloneTransmission)', function (data) {
            let loading = layer.load();
            $.ajax({
                url: '/menu/notice/send',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: "application/json;charset=utf-8",
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1, time: 3000});
                    } else {
                        layer.msg(result.message, {icon: 2, time: 3000});
                    }
                }
            })
            return false;
        });
        //发送全部
        form.on('submit(sendAll)', function (data) {
            let loading = layer.load();
            $.ajax({
                url: '/menu/notice/send/all',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: "application/json;charset=utf-8",
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1, time: 3000});
                    } else {
                        layer.msg(result.message, {icon: 2, time: 3000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>